/*jslint vars: true, forin: true, sloppy: true */
var angular = require('angular');
var probe = require('../global');
probe.service('objectStore', function (project) {

	return {
		setObject: function (obj) {
			project.cssSelectors = angular.toJson(obj);

			return this;
		},
		//for lookup
		getList: function () {
			if (project.cssSelectors) {
				return angular.fromJson(project.cssSelectors);
			}

			return [];
		},
		save: function () {
			return project.$updateObject();
		},
		//used when compiling
		getObject: function () {
			var list = angular.fromJson(String(project.cssSelectors));

			if (angular.isArray(list)) {
				var objectList = Object.create(null);

				angular.forEach(list, function (item) {
					objectList[item.name] = item.cssPath;
				});

				return objectList;
			}

			return {};
		}
	};
});
